今天是系列文最後一天,就用FileUpload畫下句點,不知道何時才會把這些文章更新到完整,不過我還是會繼續努力把文章寫得更好(真的太累了QQ)
一開始先測試一般的檔案上傳作法,在專案下新增FileUploads資料夾,驗證此網站的檔案機制沒有問題
新增FileController
public class FileController : Controller
{
// GET: File
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Upload(HttpPostedFileBase file)
{
if (file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/FileUploads"), fileName);
file.SaveAs(path);
}
return RedirectToAction("Index");
}
}
View/Index.cshtml
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<form action="@Url.Action("Upload")" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<input type="submit" />
</form>
完成上述的做法後,改用jquery ajax作法,同時將需要的更新的欄位值一併丟到ActionResult,在通過IOM.dll的setFileProperty或setFileName,新增至Aras
分享两段我做Server Method Code测试的代码:
1,从server获取method_code,编译输出cs文件
2,将输出cs文件复制到项目,进行调试。
class Program
{
{
static readonly string url = System.Configuration.ConfigurationManager.AppSettings["url"].ToString();
static Innovator inn = plminn.plminn.getInnovator(url);
static void Main(string[] args)
{
#region,1,从server获取method_code,编译输出cs文件
//string methodId = "9212C484EDF34117A9E0202BCA783C15";// "CA34E049473A40F1BAD607DE2424CBE8";//CA34E049473A40F1BAD607DE2424CBE8 ECN_engdefault ECN会签人员&通知人员默认预设
//Item item = inn.applySQL($"SELECT id,[NAME],METHOD_TYPE,METHOD_CODE FROM innovator.Method where id ='{methodId}'");
//string methodName = item.getProperty("name");
//string methodType = item.getProperty("method_type");
//string methodCode = item.getProperty("method_code");
//Aras.Iome.EvaluatorMy evaluatorMy = new Aras.Iome.EvaluatorMy();
//Type type = evaluatorMy.CompileMethod(
// new Aras.Server.Core.CacheMethodInfoMy(methodId, methodName, methodType, methodCode)
// , EventSpecificData.None
// , true
// , null
// , null);
////Type methodClass = type;
////evaluatorMy.RunMethod(methodClass, inDom, outDom, eventType, RuntimeHelpers.GetObjectValue(eventData));
#endregion
#region 2,将输出cs文件复制到项目,进行调试。
////PKG_584F1978E5C38B93FE156052CE897D5A.CLS_584F1978E5C38B93FE156052CE897D5A cLS_584F1978E5C38B93FE156052CE897D5A = new PKG_584F1978E5C38B93FE156052CE897D5A.CLS_584F1978E5C38B93FE156052CE897D5A();
////Item i_partnoapp = inn.newItem("ECN", "get");
////i_partnoapp.setID("0E6F8FB393C8407A8466EF50BD828117");
////i_partnoapp = i_partnoapp.apply();
//PKG_A8BEB6C2C37CB825ABEDF1868855AE1C.CLS_A8BEB6C2C37CB825ABEDF1868855AE1C cLS_A8BEB6C2C37CB825ABEDF1868855AE1C = new PKG_A8BEB6C2C37CB825ABEDF1868855AE1C.CLS_A8BEB6C2C37CB825ABEDF1868855AE1C();
//Item item = inn.newItem();
//item.setProperty("loginname", "S087543");
ServerMethodT serverMethodT = new ServerMethodT();
Item item = inn.newItem();
XmlDocument outDom = new XmlDocument();
XmlElement elem = outDom.CreateElement("item");
outDom.AppendChild(elem);
serverMethodT.FNCMethod(plminn.plminn.conn_t, item.dom, outDom);
}
}
}
对生产的代码进行少许改动(namespace 和 class name),将Server Method Code粘贴到methodCode()方法体中,既可以用VS做方法调试,测试方法是否ok了。
using System;
using System.IO;
using System.Xml;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.SessionState;
using System.Globalization;
using Aras.IOM;
namespace PLM_Method_PreCode
{
public class ItemMethod : Item
{
public ItemMethod(IServerConnection arg) : base(arg)
{
}
#if EventDataIsAvailable
public Item methodCode(
)
{
return methodCode( null );
}
public Item methodCode(
eventData
)
#else
public Item methodCode(
)
#endif
{
//Server Method Code
Innovator inn = this.getInnovator();
string id = this.getID();
//....
return this;
}
}
public class ServerMethodT : Aras.Server.Core.IInnovatorServerMethod
{
public void FNCMethod(
IServerConnection InnovatorServerASP,
XmlDocument inDom,
#if EventDataIsAvailable
eventData,
#endif
XmlDocument outDom
)
{
ItemMethod inItem = null;
Item outItem = null;
inItem = new ItemMethod(InnovatorServerASP);
inItem.dom = inDom;
XmlNodeList nodes = inDom.SelectNodes("//Item[not(ancestor::node()[local-name()='Item'])]");
if (nodes.Count == 1)
inItem.node = (XmlElement)nodes[0];
else
{
inItem.node = null;
inItem.nodeList = nodes;
}
outItem = inItem.methodCode(
#if EventDataIsAvailable
eventData
#endif
);
if (outItem != null)
{
outDom.ReplaceChild(outDom.ImportNode(outItem.dom.DocumentElement, true), outDom.FirstChild);
}
}
}
}